﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace RzCorportativo.Views.Cadastros
{
    [Lib.Permissao(HasValidation = true)]
    public partial class CurriculoFormatado : BasePage
    {
        public Lib.Curriculo Curriculo { get; set; }
        public List<Lib.IdiomaUsuario> Idiomas { get; set; }
        public List<Lib.Formacao> Formacoes { get; set; }
        public List<Lib.Experiencia> Experiencias { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Curriculo = Lib.Curriculo.Listar(new Lib.Curriculo() { UsuarioId = EFramework.Web.TypeExtension.LongExtension.Parse(this.Request.QueryString["usuarioId"], 0) }).FirstOrDefault();
            if (this.Curriculo == null)
            {
                this.Curriculo = new Lib.Curriculo();
                this.Curriculo.Usuario = new Lib.Usuario();
                this.Curriculo.Usuario.Nome = string.Empty;
                return;
            }
            this.Title = "Curriculo - " + this.Curriculo.Usuario.Nome;
            this.Idiomas = Lib.IdiomaUsuario.Listar(new Lib.IdiomaUsuario() { UsuarioId = (this.Curriculo.Usuario ?? new Lib.Usuario()).UsuarioId });
            this.Formacoes = Lib.Formacao.Listar(new Lib.Formacao()
            {
                UsuarioId = (this.Curriculo.Usuario ?? new Lib.Usuario()).UsuarioId
            });

            this.Experiencias = Lib.Experiencia.Listar(new Lib.Experiencia() { CurriculoId = this.Curriculo.CurriculoId });

            if (this.Idiomas != null)
                foreach (var item in this.Idiomas)
                {
                    var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.Idioma.Nome
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = "B".Equals(item.Nivel) ? "BÁSICO" : "I".Equals(item.Nivel) ? "INTERMEDIÁRIO" : "AVANÇADO"
                    });
                    this.gridIdiomas.Rows.Add(row);
                }

            if (this.Formacoes != null)
                foreach (var item in this.Formacoes)
                {
                    var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = (item.Curso ?? new Lib.Curso()).Nome
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.Instituicao
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.AnoInicio.ToString()
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.AnoFim == 0 ? string.Empty : item.AnoFim.ToString()
                    });
                    this.gridFormacao.Rows.Add(row);
                }

            if (this.Curriculo.Usuario != null && this.Curriculo.Usuario.ItensConhecimento != null)
                foreach (var item in this.Curriculo.Usuario.ItensConhecimento)
                {
                    var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.Nome
                    });
                    this.gridItensConhecimento.Rows.Add(row);
                }
            if (this.Experiencias != null)
                foreach (var item in this.Experiencias)
                {
                    var row = new System.Web.UI.HtmlControls.HtmlTableRow();
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = (item.Empresa ?? string.Empty).ToUpper()
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = ((item.Cargo ?? new Lib.Cargo()).Nome ?? string.Empty).ToUpper()
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = item.DataAdmissao.ToString("dd/MM/yyyy")
                    });
                    row.Cells.Add(new System.Web.UI.HtmlControls.HtmlTableCell()
                    {
                        InnerText = !item.DataDemissao.HasValue ? string.Empty : item.DataDemissao.Value.ToString("dd/MM/yyyy")
                    });
                    this.gridExperiencia.Rows.Add(row);
                }

            if (this.IsPostBack)
                return;

        }

    }
}